using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace CodePlex.Resourceful.Amazon.S3
{

    /*
<OperationUsage>
		<ServiceName>AmazonS3</ServiceName>
		<OperationName>GetObject</OperationName>
		<UsageType>Request</UsageType>
		<Resource>asdf</Resource>
		<StartTime>05/18/06 12:00:00</StartTime>
		<EndTime>05/18/06 13:00:00</EndTime>
		<UsageValue>1</UsageValue>
	</OperationUsage>
     */

    public class OperationUsage
    {

        private string _serviceName;
        private string _operationName;
        private string _usageType;
        private string _resource;
        private DateTime _startTime;
        private DateTime _endTime;
        private long _usageValue;


        public string ServiceName
        {
            get
            {
                return _serviceName;
            }
        }

        public string OperationName
        {
            get
            {
                return _operationName;
            }
        }

        public string UsageType
        {
            get
            {
                return _usageType;
            }
        }

        public string Resource
        {
            get
            {
                return _resource;
            }
        }

        public DateTime StartTime
        {
            get
            {
                return _startTime;
            }
        }
        public DateTime EndTime
        {
            get
            {
                return _endTime;
            }
        }

        public long UsageValue
        {
            get
            {
                return _usageValue;
            }
        }


        public static OperationUsage Parse(XmlReader reader)
        {
            OperationUsage rt = new OperationUsage();

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    rt._resource = rt._resource ?? "";
                    return rt;
                }

                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                        case "ServiceName":
                            rt._serviceName = Utils.ReadString(reader);
                            break;

                        case "OperationName":
                            rt._operationName = Utils.ReadString(reader);
                            break;
                        case "UsageType":
                            rt._usageType = Utils.ReadString(reader);
                            break;
                        case "Resource":
                            rt._resource = Utils.ReadString(reader);
                            
                            break;
                        case "StartTime":
                            rt._startTime = DateTime.Parse(Utils.ReadString(reader));
                            break;
                        case "EndTime":
                            rt._endTime = DateTime.Parse(Utils.ReadString(reader));
                            break;
                        case "UsageValue":
                            rt._usageValue = long.Parse(Utils.ReadString(reader));
                            break;


                    }
                }


            }
            return null;
          
        }
    }
}
